package database;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: leep
 * Date: 15-12-24
 * Time: 下午4:34
 * To change this template use File | Settings | File Templates.
 */
public class DBUtilsInsert {
	public static void main(String args[]) {
		ResultSetHandler handler = new BeanListHandler(Users.class);

		try {
			MysqlDataSource dataSource = new MysqlDataSource();
			dataSource.setPassword(DBConf.PASS);
			dataSource.setUser(DBConf.USER);
			dataSource.setURL(DBConf.DB_URL);
			QueryRunner queryRunner = new QueryRunner(dataSource);
			List<Users> users = (ArrayList<Users>) queryRunner.query("select * from users where id=?", handler, 3);
			System.out.println(users.get(0).name);

		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}
}
